// hyb_yl/doctorHome/pages/patientlist/patientlist.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    zimu: ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'],
    page: 0,
    list: [],
    type: 1,
    keyword: "",
    typs: "",
    zid: "",
    t_id: "",
    openid_list: [],
  },
  gochart:function(e){
    wx.navigateTo({
      url: '/hyb_yl/zhuanjiasubpages/pages/chat_list/chat_list?zid='+e.currentTarget.dataset.zid+'&openid='+e.currentTarget.dataset.openid+'&role=0&title='+e.currentTarget.dataset.names,
    })
  },
  zimu_btn: function (e) {
    var zimu = e.currentTarget.dataset.cont
    console.log(zimu)
    this.setData({
      toView: zimu
    })
  },
  more_btn:function(e){
    console.log(e)
    var list=this.data.list;
    var index=e.currentTarget.dataset.index;
    var indexs=e.currentTarget.dataset.indexs;
    
    list[indexs][index].show=!list[indexs][index].show
    console.log(list)
    this.setData({
      list:list
    })
  },



    // 修改分组
    edit_name: function (e) {
      this.setData({
        hiddenmodalput: !this.data.hiddenmodalput,
        id:e.currentTarget.dataset.id
      })
    },
    cancel1: function () {
      this.setData({
        hiddenmodalput: false
      })
    },
    confirm: function (e) {
      var that = this;
      var title = that.data.title;
      that.setData({
        hiddenmodalput: false
      })
      
    },
    fzname_input: function (e) {
      console.log(e)
      this.setData({
        title: e.detail.value
      })
    },





  choose_item: function (e) {
    var index = e.currentTarget.dataset.index;
    var openid = e.currentTarget.dataset.openid;
    var is_fenpei = e.currentTarget.dataset.is_fenpei
    var that = this;
    var openid_list = that.data.openid_list;
    if (is_fenpei) {
      wx.showModal({
        title: '提示',
        content: '该患者已被分配，是否将他分配到该专家',
        success: function (con) {
          if (con.confirm) {
            for (var i = 0; i < openid_list.length; i++) {
              if (openid_list[i] == openid) {
                openid_list.slice(i, 1);
              }
            }
            if (openid_list.indexOf(openid) < 0) {
              openid_list.push(openid)
            }
            var list = that.data.list
            console.log(list[index])
            list[index].checked = true;
            that.setData({
              list: list,
              openid_list: openid_list
            })
          }
        }
      })
    }



  },
  // 删除患者
  del: function (e) {
    var that = this;
    var id = e.currentTarget.dataset.id;
    var zid = e.currentTarget.dataset.zid;
    var openid = e.currentTarget.dataset.openid;
    wx.showModal({
      cancelColor: '提示',
      content: "是否确认删除",
      success: function (con) {
        if (con.confirm) {
          app.util.request({
            'url': "entry/wxapp/follow.del_huanzhe",
            data: {
              id: id,
              zid: zid,
              openid: openid
            },
            success: function (res) {
              that.setData({
                page: 0,
                list: [],
              })
              that.getList();
            }
          })
        }
      }
    })
  },
  huifu: function (e) {
    wx.navigateTo({
      url: '/hyb_yl/zhuanjiasubpages/pages/chat_list/chat_list?zid=' + e.currentTarget.dataset.zid + '&openid=' + e.currentTarget.dataset.openid + '&role=1&title='+e.currentTarget.dataset.title,
    })
  },
  cancel: function (e) {
    var index = e.currentTarget.dataset.index;
    var list = this.data.list
    var openid = e.currentTarget.dataset.openid;
    var that = this;
    var openid_list = that.data.openid_list;
    for (var i = 0; i < openid_list.length; i++) {
      if (openid_list[i] == openid) {
        openid_list.slice(i, 1);
      }
    }
    list[index].checked = false;
    console.log(openid_list)
    this.setData({
      list: list,
      openid_list: openid_list
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var typs = options.typs;
    var zid = options.zid;
    var t_id = options.t_id;
    if (typs == 'fenpei') {
      this.setData({
        typs: typs,
        zid: zid,
        t_id: t_id
      })
    }
  },
  // 确定分配患者
  choose: function () {
    var that = this;
    var openid_list = that.data.openid_list;
    var t_id = that.data.t_id;
    var zid = that.data.zid;
    if (openid_list.length == 0) {
      wx.showModal({
        title: '提示',
        content: "您暂未选择患者"
      })
    } else {
      app.util.request({
        'url': "entry/wxapp/follow.set_huanzhe",
        data: {
          openid: JSON.stringify(openid_list),
          t_id: t_id,
          zid: zid
        },
        success(res) {
          wx.showToast({
            title: res.data.message,
          })
          setTimeout(function () {
            wx.navigateBack({})
          }, 500)
        }
      })
    }

  },
  // 获取报道患者列表
  getList: function () {
    var that = this;
    app.util.request({
      'url': "entry/wxapp/follow.report_user",
      data: {
        zid: wx.getStorageSync('zid'),
        // type: that.data.type,
        keyword: that.data.keyword,
        // t_id: that.data.t_id,
      },
      success: function (res) {
        var list = res.data;
        that.setData({
          list: list,
        })
      }
    })
  },
  danan:function(e){
    wx.navigateTo({
      url: '/hyb_yl/zhuanjiasubpages/pages/danganList/danganList?openid='+e.currentTarget.dataset.openid+'&doc=1&type=1&titlme='+e.currentTarget.dataset.names,
    })
  },
  // 输入关键词
  changekeyword: function (e) {
    this.setData({
      keyword: e.detail.value
    })
  },
  search: function () {
    var that = this;
    that.setData({
      list: [],
      page: 0
    })
    that.getList();
  },
  // 修改查询条件
  changetype: function (e) {
    this.setData({
      type: e.currentTarget.dataset.type,
      list: [],
      page: 0
    })
    this.getList();
  },
  // 跳转详情
  todetail: function (e) {
    var that = this;
    wx.navigateTo({
      url: '/hyb_yl/doctorHome/pages/acceptpatient/acceptpatient?id=' + e.currentTarget.dataset.id + '&typs=fenzu&j_id=' + e.currentTarget.dataset.j_id,
    })
  },
  // 去分组
  
  fenzu:function(e){
    var that = this
    var id = e.currentTarget.dataset.id
    var j_id = e.currentTarget.dataset.j_id
    var f_id = e.currentTarget.dataset.f_id
    var back_orser = e.currentTarget.dataset.back_orser
    var zid = wx.getStorageSync('zid')
    wx.navigateTo({
      url: '/hyb_yl/mysubpages/pages/grouping_list/grouping_list?a_id=' + id + '&j_id=' + j_id + '&typs=fenzu&zid=' + zid + '&f_id=' + f_id + '&back_orser=' + back_orser,
    })
  },
  agree(e) {
    var that = this
    var id = e.currentTarget.dataset.id
    var j_id = e.currentTarget.dataset.j_id
    var zid = wx.getStorageSync('zid')
    app.util.request({
      'url': 'entry/wxapp/zhuanjia.updateqianyue',
      data: {
        id: id
      },
      success: function (res) {
        console.log(res)
        wx.showModal({
          title: '提示',
          content: '是否立即分组',
          success: function (con) {
            if (con.confirm) {
              wx.navigateTo({
                url: '/hyb_yl/mysubpages/pages/grouping_list/grouping_list?a_id=' + id + '&j_id=' + j_id + '&typs=fenzu&zid=' + zid,
              })
            }
          }
        })
      }
    })
  },
  disagree(e) {
    var that = this
    var id = e.currentTarget.dataset.id
    var zid = wx.getStorageSync('zid')
    app.util.request({
      'url': 'entry/wxapp/zhuanjia.updatejujueqianyue',
      data: {
        id: id
      },
      success: function (res) {
        wx.navigateBack({})
      }
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var that = this;
    that.getList();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})